<template>
	<view class="order">
		<view class="order-top">
			<view class="order-tabbar">
				<liuyuno-tabs :tabData="catList" :activeIndex="tabIndex" @tabClick='tab' class="nav" />
			</view>
		</view>
		<view class="order-list">
			<view class="order" v-for="item in orders">
				<order-item :dataSource='item'></order-item>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				catList: [{
					"id": "0",
					"name": "全部"
				}, {
					"id": "1",
					"name": "待付款"
				}, {
					"id": "2",
					"name": "待发货"
				}, {
					"id": "3",
					"name": "已发货"
				}, {
					"id": "4",
					"name": "退款/售后"
				}],
				tabIndex: 0,
				orders: []
			}
		},
		onLoad(options) {
			if (options.status && options.status < this.catList.length) {
				this.tabIndex = parseInt(options.status);
			} else {
				this.tabIndex = 0
			}
			this.initData()
		},
		computed: {
			isWX() {
				return this.$store.getters.isWX
			},
			orderList() {
				return this.$store.getters.getOrderList
			}
		},
		methods: {
			initData(){
				if(this.tabIndex == 0){
					this.orders = this.orderList
				} else {
					let orderList = this.orderList.filter(res => {
						return res.status == this.catList[this.tabIndex]
					})
					this.orders = orderList
				}
				
			},
			tab(e) {
				this.tabIndex = e
				this.initData()
			}
		}
	}
</script>

<style lang="scss" scoped>
	.order {
		width: 100%;
		display: flex;
		flex-direction: column;
	}

	.order-top {
		position: sticky;
		top: 0;
		z-index: 10;
		background: #fff;
		padding: 20rpx 0;
	}

	.order-list {
		padding: 20rpx;
	}
</style>